#ifndef __IPC_RV_H__
#define __IPC_RV_H__
#include "g_type.h"
#include "ringbuf.h"
#include "ipc_debug.h"

#ifdef __cplusplus
extern "C" {
#endif

#define pIPC_RVBaseAddr     ((uint32_t)(0x6fffc))

#define IPC_RVBuf_Size_t    G_RingBuf_Size_t      
#define MsgPRINT            PrintMsg            /*Msg Print*/
#define MsgHEADLEN          (4)                 /*Msg 消息头长度*/
#define SyncMsgLEN          (MsgHEADLEN+8)      /*同步消息长度*/
#define SyncChLEN           (SyncMsgLEN+sizeof(G_RingBuf_TyperDef))   /*同步通道长度*/

#define MsgPRINT_DIR        MsgPRINT_DIR_EX
#define DEBUG_PRINT(x)      IPC_DEBUG_LOG(IPC_DEBUG_Msg,(x))


typedef enum {
    IPC_SUCCESS = 0,
    IPC_ERROR_TIME_OUT = -1,
    IPC_ERROR_SEND = -2,
    IPC_ERROR_RECV = -3,
    IPC_ERROR_PARSE = -4,
	IPC_ERROR_RET = -5,
}G_IpcStatusTypeDef;

#define IPC_TYPE_SYSTEM     (1)
#define IPC_TYPE_CAMERA     (2)
#define IPC_TYPE_DEBUG      (3)
#define IPC_TYPE_EVENT      (4)
#define IPC_TYPE_IFLASH     (5)
#define IPC_TYPE_FP         (6)
#define IPC_TYPE_ICE_DAP    (7)

#define IPC_TYPE_SYNC       (0<<7)
#define IPC_TYPE_ASYNC      (1<<7)


enum _IPC_RV_DIR_ENUM
{
    M02RV = 0,
    RV2M0,
};
typedef enum _IPC_RV_DIR_ENUM G_IPC_RV_DIR_ENUM;

struct _IPC_RV_TypeDef
{
    G_RingBuf_TyperDef * Sync[2];     //SYNC  CH
    G_RingBuf_TyperDef * ASync[2];    //ASYNC CH  
};
typedef struct _IPC_RV_TypeDef   G_IPC_RV_TypeDef;
typedef struct _IPC_RV_TypeDef *G_pIPC_RV_TypeDef;

#define IPC_RVBaseAddr      ((uint32_t)(*(volatile uint32_t *)(pIPC_RVBaseAddr)))
#define pIPC_RVCB           ((G_pIPC_RV_TypeDef)(IPC_RVBaseAddr))


/*
type: bit7: 0: sync   同步消息需要有Ack
            1: async  异步消息
      bit6~0：service
            0: ACK
            1：debug
            2：camera
            3: system
        other：NULL
opcode：


M0----->RV
service 1：debug
cmd_00:

service 2：camera
cmd_00：send camera para
cmd_01: set camera IO
cmd_02: get camera IO
cmd_03: set 

RV----->M0
service 1:debug
cmd_0:debug print

service 2:camera
cmd_0:decode OK

*/

typedef struct
{
    uint8_t  type;   
    uint8_t  opcode;
    uint16_t DataLen;
    uint8_t *pData;
}G_Message_TypeDef;


G_Boolean G_IPC_RV_Init(uint8_t *baseAddr, IPC_RVBuf_Size_t size);

G_Boolean G_IPC_RV_Send_SyncMsg(G_IPC_RV_DIR_ENUM ch,G_Message_TypeDef *tMsg, G_Message_TypeDef *rMsg, uint32_t TimeOut);

G_Boolean G_IPC_RV_Recv_SyncMsg(G_IPC_RV_DIR_ENUM ch,G_Message_TypeDef *rMsg,uint32_t TimeOut);

G_Boolean G_IPC_RV_Send_Msg(G_IPC_RV_DIR_ENUM ch,G_Message_TypeDef *tMsg,uint32_t TimeOut);

G_Boolean G_IPC_RV_Recv_Msg(G_IPC_RV_DIR_ENUM ch,G_Message_TypeDef *rMsg,uint32_t TimeOut);

#ifdef __cplusplus
}
#endif

#endif
